<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/vue"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .container {
      position: absolute;
      width: 200px;
      height: 400px;
      background-color: pink;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }
  </style>
</head>

<body>
  <div id="root"></div>
  <script>
    /* 
      
    */

    const app = Vue.createApp({
      template: `
      <div class="container" >
        <todolist />
      </div>
    `,
    })
    app.component('todolist', {
      template: `
      <div class="container" >
        <input v-model="todo" />
        <button @click="handleClick" >添加</button>
        <ul>
          <li v-for="(item,index) in list" :key="index">{{index + 1}}：{{item}}</li>
        </ul>
      </div>
      `,
      setup(props, context) {
        const { ref, reactive } = Vue
        const list = reactive([])
        let todo = ref('')
        function handleClick() {
          list.push(todo.value)
          todo.value = ''
        }
        return {
          todo,
          list,
          handleClick
        }
      }
    })
    const vm = app.mount('#root');

  </script>
</body>

</html>